package com.example.administrator.commonlyused;

import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;
import android.widget.Toast;


import com.example.administrator.commonlyused.adpter.AnnotationItemListAdapter;
import com.example.administrator.commonlyused.bean.AnnotationItem;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Bean;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ItemClick;
import org.androidannotations.annotations.ItemLongClick;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.List;

@EActivity(R.layout.activity_main2)
public class AnnotationActivity extends AppCompatActivity {
    @ViewById
    ListView listview;

    @Bean
    AnnotationItemListAdapter adapter;

    @AfterViews
    void init()
    {
        listview.setAdapter(adapter);

        initData();
    }

    private void initData()
    {
        List<AnnotationItem> items = new ArrayList<AnnotationItem>();

        for (int i = 0; i < 20; i++)
        {
            items.add(new AnnotationItem("标题" + i, "正文" + i + "\n长按删除", R.mipmap.ic_launcher));
        }
        adapter.update(items);
    }


    /**
     * 名字必须是这个
     */
    @ItemClick
    void listviewItemClicked(AnnotationItem item)
    {
        Toast.makeText(this, "点击了" + item.toString(), Toast.LENGTH_SHORT).show();
    }

    /**
     * 名字必须是这个
     */
    @ItemLongClick
    void listviewItemLongClicked(AnnotationItem item)
    {
        adapter.delete(item);
    }
}